/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.BaseDAO;
import cn.ekuma.epos.db.table.I_Payment;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.bean.Payment;

/**
 *
 * @author Administrator
 */
public class PaymentDAO extends BaseDAO<Payment>{

    public PaymentDAO(I_Session s) {
        super(s);
    }

    
    @Override
    public TableDefinition getTable() {
       return new TableDefinition(s,
                      "PAYMENTS",
                    new Field[]{
                        new Field(I_Payment.ID,Datas.STRING,Formats.STRING),
                        new Field(I_Payment.RECEIPT,Datas.STRING,Formats.STRING),
                        new Field(I_Payment.PAYMENT,Datas.STRING,Formats.STRING),
                        new Field(I_Payment.TOTAL,Datas.DOUBLE,Formats.DOUBLE),
                        new Field(I_Payment.TRANSID,Datas.STRING,Formats.STRING),
                        new Field(I_Payment.RETURNMSG,Datas.BYTES,Formats.BYTEA),
                        new Field(I_Payment.LASTMODIFIED,Datas.TIMESTAMP,Formats.TIMESTAMP)
                    },
                    new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, Payment obj) throws BasicException {
                            dp.setString(1, obj.getId());
                            dp.setString(2, obj.getReceiptID());
                            dp.setString(3, obj.getM_sName());
                            dp.setDouble(4, obj.getM_dTotal());
                            dp.setString(5, obj.getM_transactionID());
                            dp.setBytes(6, (byte[]) Formats.BYTEA.parseValue( obj.getReturnMessage()));
                            dp.setTimestamp(7,obj.getLastModified());
    }

    @Override
    public Class getSuportClass() {
        return Payment.class;
    }

    public Payment readValues(DataRead dr,Payment obj) throws BasicException {
        if(obj==null)
        	obj=new Payment();
        obj.setId(dr.getString(1));
        obj.setReceiptID(dr.getString(2));
        obj.setM_sName(dr.getString(3));
        obj.setM_dTotal(dr.getDouble(4));
        obj.setM_transactionID(dr.getString(5));
        obj.setReturnMessage(Formats.BYTEA.formatValue(dr.getBytes(6)));
        obj.setLastModified(dr.getTimestamp(7));
        return obj;
    }

}
